//
//  YAStatusTopView.swift
//  KeepCliming
//
//  Created by 鱼龙之梦 on 15/9/6.
//  Copyright © 2015年 panyanzhi. All rights reserved.
//

import UIKit

class YAStatusTopView: UIView {
     //MARK:--- 懒加载加入子控件
    private lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLabel:UILabel = UILabel(title: "姓名", color: UIColor.darkGrayColor(), fontSize: 14)
    private lazy var memberView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    private lazy var timeLable:UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 10)
    private lazy var sourceLable:UILabel = UILabel(title: "来自 新浪微博", color: UIColor.darkGrayColor(), fontSize: 10)
    private lazy var vipView:UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))
    var statusVM:YAStatusVM?{
        didSet{
            nameLabel.text = statusVM?.status.user?.name
            iconView.sd_setImageWithURL(statusVM?.userIconURL)
            vipView.image = statusVM?.userVipImage
            memberView.image = statusVM?.userMemberImage
            timeLable.text = NSDate.sinaDate(statusVM?.status.created_at ?? "")?.dateDescription
            sourceLable.text = statusVM?.status.source
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nameLabel)
        addSubview(iconView)
        addSubview(vipView)
        addSubview(memberView)
        addSubview(sourceLable)
        addSubview(timeLable)
        
        setupUIConstrain()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     //MARK:--- 用UIView+AutoLayout框架
    
    private func setupUIConstrain(){
        let offset = CGPoint(x: YAStatusCellMargin, y: 0)
        //在父控件内左上，宽高固定，
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: YAStatusIconWidth, height: YAStatusIconWidth),offset:CGPoint(x: YAStatusCellMargin, y: YAStatusCellMargin))
        //在iconView右上，宽高随图片
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil,offset:offset)
        //在nameLabel右上，宽高随图片
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil,offset:offset)
        //在iconView右下，宽高随文本
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil,offset:offset)
        //在timeLable右下，宽高随文本
        sourceLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLable, size: nil,offset: offset)
        //在iconView内右下，宽高随图片
        vipView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil,offset:CGPoint(x:8,y:8))
        
        
    }
}
